import 'package:flutter/material.dart';
import 'package:poet/pages/recommend_page/allusions.dart';
import 'package:poet/pages/recommend_page/recommend.dart';
import 'package:poet/pages/theme_config.dart';

class RecommendPage extends StatefulWidget {
  RecommendPage({Key key}) : super(key: key);

  @override
  _RecommendPage createState() {
    return new _RecommendPage();
  }
}

class _RecommendPage extends State<RecommendPage>
    with SingleTickerProviderStateMixin {
  TabController _tabController;
  List _tabs = ["推荐", "典故"];
  List<Widget> _widgets;

  @override
  void initState() {
    super.initState();
    _tabController = TabController(length: _tabs.length, vsync: this);
    _widgets = [Recommend(), Allusions()];
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        //导航栏
        title: Text("首页"),
        actions: <Widget>[
          //导航栏右侧菜单
          IconButton(icon: Icon(Icons.more_horiz), onPressed: () {}),
        ],
        bottom: TabBar(
          tabs: _tabs.map((e) => Tab(text: e)).toList(),
          controller: _tabController,
        ),
      ),
      body: TabBarView(
        controller: _tabController,
        children: _widgets,
      ),
    );
  }
}

class RecommendButton extends StatelessWidget {
  final String text;
  final GestureTapCallback onTap;

  const RecommendButton(this.text, {this.onTap});

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: this.onTap,
      child: Padding(
        padding: EdgeInsets.all(4.0),
        child: Text(
          '$text',
          textScaleFactor: 1.2,
        ),
      ),
    );
  }
}
